﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Data
Imports System.Windows.Forms
Imports DevComponents.DotNetBar.Controls
Imports DevComponents.Editors.DateTimeAdv
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.DTO
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.General
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.BUSS

Namespace DoAnQuanLyBanHang.DAO
    Public Class XuatHangCtrl
        Private m_XuatHangData As New XuatHangData()
        Private m_XuatHangInfo As New XuatHangInfo()

        Public Sub HienThiComboBox(cbx As ComboBox)
            Dim m_DT As DataTable = m_XuatHangData.LayXuatHang()
            cbx.DataSource = m_DT
            cbx.DisplayMember = "MaPhieu"

            cbx.ValueMember = "MaPhieu"
        End Sub

#Region "hien thi"
        Public Sub HienThi(Dgv As DataGridView, bvn As BindingNavigator)
            Dim bs As New BindingSource()

            bs.DataSource = m_XuatHangData.LayXuatHang()
            bvn.BindingSource = bs
            Dgv.DataSource = bs
        End Sub

        Public Shared Function LayDsXuatHangTheoMa(MaPhieu As [String]) As IList(Of XuatHangInfo)
            Dim ds As IList(Of XuatHangInfo) = New List(Of XuatHangInfo)()

            Dim data As New XuatHangData()
            Dim tbl As DataTable = data.LayDSXuatHangTheoMa(MaPhieu)

            Dim XuatHang As IList(Of XuatHangInfo) = New List(Of XuatHangInfo)()

            For Each row As DataRow In tbl.Rows
                Dim XH As New XuatHangInfo()

                Dim m_MH As New MatHangInfo()
                m_MH.TenMH = Convert.ToString(row("TenMH"))
                m_MH.MaMH = Convert.ToString(row("MaMH"))
                Dim m_KH As New KhachHangInfo()
                m_KH.HoTen = Convert.ToString(row("HoTen"))
                m_KH.MaKH = Convert.ToString(row("MaKH"))
                Dim m_NV As New NhanVienInfo()
                m_NV.HoTen = Convert.ToString(row("HoTenNV"))
                m_NV.MaNV = Convert.ToString(row("MaNV"))
                Dim m_LoaiTien As New LoaiTienInfo()
                m_LoaiTien.LoaiTien = Convert.ToString(row("LoaiTien"))
                Dim m_LoaiGD As New LoaiGiaoDichInfo()
                m_LoaiGD.TenGiaoDich = Convert.ToString(row("TenLoaiGiaoDich"))

                XH.MaPhieu = Convert.ToString(row("MaPhieu"))
                XH.SoLuong = Convert.ToString(row("SoLuong"))
                XH.GiaBan = Convert.ToString(row("GiaBan"))
                XH.ThanhTien = Convert.ToString(row("ThanhTien"))
                XH.NgayXuat = Convert.ToDateTime(row("NgayXuat"))
                XH.MaMH = m_MH
                XH.MaKH = m_KH
                XH.MaNV = m_NV
                XH.MaLoaiGiaoDich = m_LoaiGD
                XH.MaLoaiTien = m_LoaiTien
                XuatHang.Add(XH)
            Next
            Return XuatHang
        End Function

        Public Sub HienThi(dGV As DataGridViewX, bN As BindingNavigator, txtMaPhieu As TextBoxX, dtNgayXuat As DateTimeInput, txtSoLuong As TextBoxX, txtGiaBan As TextBoxX, _
         txtThanhTien As TextBoxX, cmbTenMH As ComboBoxEx, cmbTenKH As ComboBoxEx, cmbTenNV As ComboBoxEx, cmbLoaiGiaoDich As ComboBoxEx, cmbLoaiTienGui As ComboBoxEx)
            Dim bS As New BindingSource()
            bS.DataSource = m_XuatHangData.LayXuatHang()

            txtMaPhieu.DataBindings.Clear()
            txtMaPhieu.DataBindings.Add("Text", bS, "MaPhieu")

            dtNgayXuat.DataBindings.Clear()
            dtNgayXuat.DataBindings.Add("Value", bS, "NgayXuat")

            txtSoLuong.DataBindings.Clear()
            txtSoLuong.DataBindings.Add("Text", bS, "SoLuong")

            txtGiaBan.DataBindings.Clear()
            txtGiaBan.DataBindings.Add("Text", bS, "GiaBan")

            txtThanhTien.DataBindings.Clear()
            txtThanhTien.DataBindings.Add("Text", bS, "ThanhTien")

            cmbLoaiGiaoDich.DataBindings.Clear()
            cmbLoaiGiaoDich.DataBindings.Add("SelectedValue", bS, "MaLoaiGiaoDich")

            cmbTenMH.DataBindings.Clear()
            cmbTenMH.DataBindings.Add("SelectedValue", bS, "MaMH")

            cmbTenKH.DataBindings.Clear()
            cmbTenKH.DataBindings.Add("SelectedValue", bS, "MaKH")

            cmbTenNV.DataBindings.Clear()
            cmbTenNV.DataBindings.Add("SelectedValue", bS, "MaNV")

            cmbLoaiTienGui.DataBindings.Clear()
            cmbLoaiTienGui.DataBindings.Add("SelectedValue", bS, "MaLoaiTien")

            bN.BindingSource = bS
            dGV.DataSource = bS
        End Sub
#End Region

#Region "Them moi"
        Public Function ThemDongMoi() As DataRow
            Return m_XuatHangData.ThemDongMoi()
        End Function
        Public Sub ThemMoi(m_Row As DataRow)
            m_XuatHangData.ThemXuatHang(m_Row)
        End Sub
#End Region

#Region "Luu"
        Public Function LuuXuatHang() As Boolean
            Return m_XuatHangData.LuuXuatHang()
        End Function

        Public Sub LuuXuatHang(maphieu As [String], mamh As [String], makh As [String], manv As [String], soluong As Single, giaban As Single, _
         thanhtien As Single, ngayxuat As DateTime, maloaitien As [String], maloaigd As [String])
            m_XuatHangData.LuuXuatHang(maphieu, mamh, makh, manv, soluong, giaban, _
             thanhtien, ngayxuat, maloaitien, maloaigd)
        End Sub
#End Region

#Region "Sửa"
        Public Sub SuaXuatHang(maphieu As [String], mamh As [String], makh As [String], manv As [String], soluong As Single, giaban As Single, _
         thanhtien As Single, ngayxuat As DateTime, maloaitien As [String], maloaigd As [String])
            m_XuatHangData.SuaXuatHang(maphieu, mamh, makh, manv, soluong, giaban, _
             thanhtien, ngayxuat, maloaitien, maloaigd)
        End Sub
#End Region

#Region "Xóa"
        Public Sub XoaXuatHang(maphieu As [String], mamh As [String], makh As [String], manv As [String])
            m_XuatHangData.XoaXuatHang(maphieu, mamh, makh, manv)
        End Sub
#End Region
    End Class
End Namespace
